txkui.parse();
//修改需要的id
var assayId = ""; //孕检信息
var diacrisisId = ""; //主键id
var outpatientNo = ""; //门诊号
var patientCode = ""; //患者代号
var patientHisId = ""; //His主键

var isValid="";
var patientBirthday="";//患者生日

var panduan = "1"; //判断是修改还是新增    2：修改   1：新增
var xuanze = 1;
var xchgs = 0;
var patientCardId;
//上一步
var onclick1 = function() {
    var form = new mini.Form("#updatezdxx");
    form.validate();
    if (form.isValid() == false) {
        mini.alert("请完善您的数据");
        return;
    };
        $('.nextClick').css('background', '#25cdcb')
        if (xuanze > 1) {
            xuanze--;
            showcoten(xuanze);
            if (xuanze === 1) {
                $('.backClick').css('background', '#dcdcdc')
            }
        }
    }
    //下一步
var onclick2 = function() {
    var form = new mini.Form("#updatezdxx");
    form.validate();
    if (form.isValid() == false) {
        mini.alert("请完善您的数据");
        return;
    };
        $('.backClick').css('background', '#25cdcb')
        if (xuanze < 3) {
            xuanze++;
            showcoten(xuanze)
            if (xuanze === 3) {
                $('.nextClick').css('background', '#dcdcdc');
                $('.submitClick').css('background', '#25cdcb');
                // $('.submitClick').on("click",)
            }
        }
    }
    //显示第几个输入块
var showcoten = function(num) {
        var classname = '.bottoncontent' + num;
        $(classname).siblings().fadeOut("slow");
        $(classname).fadeIn("slow");
        if ($('.Carouselicon').children().eq(num - 1).hasClass("Carouseldiv")) {
            $('.Carouselicon').children().eq(num).removeClass('Carouseldiv');
        } else {
            $('.Carouselicon').children().eq(num - 1).addClass('Carouseldiv');
        }
    }
    //-----------------------------------------------------------------------------------------------多胎操作
    //=====================================单胎

mini.get('changechaosheng').on("valuechanged", function(e) {
    if (this.getValue() === '1') {
        $('.dantaidiv').css('display', 'flex')
		$('.duotaidiv').css('display', 'none')
    } else if (this.getValue() === '2') {
        $('.duotaidiv').css('display', 'flex')
		$('.dantaidiv').css('display', 'none')
    }
});
$('#changechaosheng').click(function(){
	if (mini.get('changechaosheng').getValue() === '1') {
	    $('.dantaidiv').css('display', 'flex')
		$('.duotaidiv').css('display', 'none')
	} else if (mini.get('changechaosheng').getValue() === '2') {
	    $('.duotaidiv').css('display', 'flex')
		$('.dantaidiv').css('display', 'none')
	}
})
//单胎的检查次数
var dtjccs = 1;
//添加单胎检查次数
function inserttab() {
    dtjccs++
    var tabs = mini.get("dantaitabs");
    //add tab
    var tab = {
        title: "第" + dtjccs + "次检查",
        showCloseButton: true
    };
    tab = tabs.addTab(tab);
    //tab body
    var el = tabs.getTabBodyEl(tab);
    // el.innerHTML = $("#jianchatab").tmpl();
    $(el).append($("#jianchatab").tmpl({
        "index": dtjccs - 1
    }));
    //active tab
    tabs.activeTab(tab);
    // mini.parse();
    txkui.parse();
}
//减少检查次数
mini.get("dantaitabs").on("closeclick", function(e) {
        dtjccs--;
        var tabs = mini.get("dantaitabs");
        for (var i = 0; i < dtjccs; i++) {
            tab = tabs.tabs[i];
            tabs.updateTab(tab, {
                title: "第" + (i + 1) + "次检查"
            });
        }
        return;
    })
    //==================================================多胎
    //多胎胎数
var duotaishu = 1;
//添加多胎胎数
function addduotai() {
    duotaishu++;
    //增加上面的基本信息
    $(".delduotai").remove();
    $(".duotaishutab1").append($("#duotaitab1").tmpl({
        indexs: duotaishu,
        inde: duotaishu - 1
    }));
    var tabs = mini.get("duotaitabs");
    for (var s = 0; s < tabs.getTabs().length; s++) {
        var el = tabs.getTabBodyEl(tabs.getTab(s));
        $(el).find(".tab1conten").append($("#duotaitab2").tmpl({
            index: duotaishu,
            tabindex: s,
            taishu: duotaishu - 1
        }))
    }
    txkui.parse();
};
var duotaijianchas = 1;
//新增多胎检查次数
function insertduotaitab() {
    duotaijianchas++
    var tabs = mini.get("duotaitabs");
    var tab = {
        title: "第" + duotaijianchas + "次检查",
        showCloseButton: true
    };

    tab = tabs.addTab(tab);
    var el = tabs.getTabBodyEl(tab);
    $(el).append($("#duotaitab3").tmpl({
        index: duotaijianchas - 1
    }))
    for (var i = 0; i < duotaishu; i++) {
        $(el).find(".tab1conten").append($("#duotaitab2").tmpl({
            index: i + 1,
            tabindex: duotaijianchas - 1,
            taishu: i
        }))
    }
    tabs.activeTab(tab);
    txkui.parse();

}
//关闭多胎
mini.get("duotaitabs").on("closeclick", function(e) {
        duotaijianchas--;
        var tab;
        var tabs = mini.get("duotaitabs");
        for (var i = 0; i < duotaijianchas; i++) {
            tab = tabs.tabs[i];
            tabs.updateTab(tab, {
                title: "第" + (i + 1) + "次检查"
            });
        }
        return;
    })
    //--------------------------------------------------------------------------------------------多胎
    //提交
function onclick3() {
    var loadingWin =mini.loading("请稍后...", "等待");
    var form = new mini.Form("#updatezdxx");
    form.validate();
	if (form.isValid() == false) {
        mini.hideMessageBox(loadingWin);
	    return;
    }
    var biglist = form.getData(); //获取整个form的数据
    var xchlist = []; //现存孩集合
    var xchsj = $('.xchlist').find(".xchxx"); //现存孩数量
    //获取现存孩数据
    xchsj.each(function(index, _this) {
        if(mini.getbyName('gender', _this).getValue()===""||mini.getbyName('age', _this).getValue()===""){
            return;
        }
        var xch = {
            "childBirthday": "",
            "childSex": mini.getbyName('gender', _this).getValue(),
            "childAge": mini.getbyName('age', _this).getValue(),
            "childAgeMonth": mini.getbyName('childAgeMonth', _this).getValue(),
            "childRemark": mini.getbyName('beizhu', _this).getValue(),
            "childId": mini.getbyName('childId', _this).getValue()
        }
        xchlist.push(xch);
    })

    biglist.existingChild = xchlist; //讲现存孩数据赋值给大form数据
    //判断超声检查单胎多胎
    if (biglist.tblDiacrisisInfo.fetusesTypeId === "1") {
        //单胎获取数据
        var dantaiform = new mini.Form("#dantaiform");
        var dantaiformlist = dantaiform.getData();
        for (var i = 0; i < dantaiformlist.fetusDetail.length; i++) {
            if (JSON.stringify(dantaiformlist.fetusDetail[i]) === "{}") {
                dantaiformlist.fetusDetail.splice(i, 1);
            }
        }
        biglist.fetusDetail = dantaiformlist;
    } else if (biglist.tblDiacrisisInfo.fetusesTypeId === "2") {
        //多胎获取数据
        var duotaiform = new mini.Form("#duotaiform");
        var duotaiformlist = duotaiform.getData();
        for (var i = 0; i < duotaiformlist.fetusDetail.length; i++) {
            if (JSON.stringify(duotaiformlist.fetusDetail[i]) === "{}") {
                duotaiformlist.fetusDetail.splice(i, 1);
            }
        }
        var duotsubmit = [];
        for (var i = 0; i < duotaiformlist.fetusDetail.test.length; i++) {
            var jibenshuju = { //类型：Object  可有字段  备注：B超检查
                "fetusId": duotaiformlist.fetusDetail.test[i].fetusId, //胎id
                "inspectTime": duotaiformlist.fetusDetail.inspectTime, //类型：String  可有字段  备注：检查日期
                "gestWeeks": duotaiformlist.fetusDetail.gestWeeks, //类型：Number  可有字段  备注：孕龄周
                "gestDays": duotaiformlist.fetusDetail.gestDays, //类型：Number  可有字段  备注：孕龄天
                "inspectionHospital": duotaiformlist.fetusDetail.inspectionHospital, //类型：String  可有字段  备注：检查医院
                "nt": duotaiformlist.fetusDetail.test[i].nt, //类型：Number  可有字段  备注：NT
                "crl": duotaiformlist.fetusDetail.test[i].crl, //类型：Number  可有字段  备注：CRL
                "isNasal": duotaiformlist.fetusDetail.test[i].isNasal, //类型：String  可有字段  备注：有无鼻骨
                "siteId": duotaiformlist.fetusDetail.test[i].siteId, //类型：String  可有字段  备注：胎盘位置ID
                "siteName": "", //类型：String  可有字段  备注：胎盘位置
                "bAbnormalId": duotaiformlist.fetusDetail.test[i].bAbnormalId, //类型：String  可有字段  备注：B超异常ID
                "bAbnormal": "", //类型：String  可有字段  备注：B超异常
                "chorionicId": duotaiformlist.fetusDetail.chorionicId, //类型：String  可有字段  备注：绒毛膜性ID
                "chorionicName": "", //类型：String  可有字段  备注：绒毛膜性
                "fetusRemark": duotaiformlist.fetusDetail.test[i].fetusRemark, //类型：String  可有字段  备注：备注
                "fetusDetail": []
            }
            for (var j = 0; j < duotaiformlist.fetusDetail.test1.length; j++) {
                var jianchatai = { //类型：Object  可有字段  备注：胎儿检查详细
                    "fetusDetailId": duotaiformlist.fetusDetail.test1[j].ctest[i].fetusDetailId, //子表主键id修改需要
                    "inspectionTime": duotaiformlist.fetusDetail.test1[j].inspectionTime, //类型：String  可有字段  备注：检查日期
                    "gestWeeks": duotaiformlist.fetusDetail.test1[j].gestWeeks, //类型：Number  可有字段  备注：孕龄周
                    "gestDays": duotaiformlist.fetusDetail.test1[j].gestDays, //类型：String  可有字段  备注：孕龄天
                    "inspectionHospital": duotaiformlist.fetusDetail.test1[j].inspectionHospital, //类型：String  可有字段  备注：检查医院
                    "bpd": duotaiformlist.fetusDetail.test1[j].ctest[i].bpd, //类型：Number  可有字段  备注：双顶径长度
                    "crl": duotaiformlist.fetusDetail.test1[j].ctest[i].crl, //类型：Number  可有字段  备注：HC
                    "ac": duotaiformlist.fetusDetail.test1[j].ctest[i].ac, //类型：String  可有字段  备注：AC
                    "fl": duotaiformlist.fetusDetail.test1[j].ctest[i].fl, //类型：String  可有字段  备注：FL
                    "efw": duotaiformlist.fetusDetail.test1[j].ctest[i].efw, //类型：String  可有字段  备注：EFW
                    "afi": duotaiformlist.fetusDetail.test1[j].ctest[i].afi, //类型：String  可有字段  备注：AFI
                    "afv": duotaiformlist.fetusDetail.test1[j].ctest[i].afv, //类型：String  可有字段  备注：AFV
                    "bloodFlow": duotaiformlist.fetusDetail.test1[j].ctest[i].bloodFlow, //类型：String  可有字段  备注：血流
                    "umbilicalInsertion": duotaiformlist.fetusDetail.test1[j].ctest[i].umbilicalInsertion, //类型：String  可有字段  备注：脐带插入
                    "siteId": duotaiformlist.fetusDetail.test1[j].ctest[i].siteId, //类型：String  可有字段  备注：胎盘位置ID
                    "siteName": "mock", //类型：String  可有字段  备注：胎盘位置
                    "bAbnormalId": duotaiformlist.fetusDetail.test1[j].ctest[i].bAbnormalId, //类型：String  可有字段  备注：B超异常ID
                    "bAbnormal": "mock", //类型：String  可有字段  备注：B超异常
                    "chorionicId": duotaiformlist.fetusDetail.chorionicId, //类型：String  可有字段  备注：绒毛膜性ID
                    "chorionicName": "mock", //类型：String  可有字段  备注：绒毛膜性
                    "fetusDetailRemark": duotaiformlist.fetusDetail.test1[j].ctest[i].fetusDetailRemark //类型：String  可有字段  备注：备注
                }
                jibenshuju.fetusDetail.push(jianchatai)
            }
            duotsubmit.push(jibenshuju)
        }
        biglist.fetusDetail = duotsubmit;
    }
    //获取居住环境
    var patient = mini.get("jzhjselect");
    var patientlivelist = patient.getSelecteds();
    var patientlive = [];
    for (var juzhu = 0; juzhu < patientlivelist.length; juzhu++) {
        if (patientlivelist[juzhu].id === "") {
            continue;
        }
        patientlive.push({
            "patientLiveId": patientlivelist[juzhu].id,
            "patientLiveName": patientlivelist[juzhu].text
        })
    }
    var dataJson = {
        //基本信息
        "tblDiacrisisInfo": {
            "patientCode": patientCode,
            "diacrisisId": diacrisisId,
            "recordTime": biglist.tblDiacrisisInfo.recordTime,
            "outpatientNo": outpatientNo, //类型：String  必有字段  备注：门诊号
            "patientId": "", //类型：String  必有字段  备注：患者信息ID
            "hisId":patientHisId,
            "patientName": biglist.tblDiacrisisInfo.patientName, //类型：String  必有字段  备注：患者姓名
            "patientPy": "", //类型：String  必有字段  备注：姓名拼音
            "patientCardId": biglist.tblDiacrisisInfo.patientCardId, //类型：String  可有字段  备注：患者身份证号
            "patientSex": "", //类型：String  可有字段  备注：患者性别
            "patientBirthday": patientBirthday, //类型：String  可有字段  备注：出生日期
            "patientRaceId": biglist.tblDiacrisisInfo.patientRaceId, //类型：String  可有字段  备注：患者民族ID
            "patientRace": "", //类型：String  可有字段  备注：患者民族
            "patientReligionId": biglist.tblDiacrisisInfo.patientReligionId, //类型：String  可有字段  备注：宗教信仰ID
            "patientReligion": "", //类型：String  可有字段  备注：宗教信仰
            "patientAge": biglist.tblDiacrisisInfo.patientAge, //类型：Number  可有字段  备注：患者年龄
            "patientOccupationId": biglist.tblDiacrisisInfo.patientOccupationId, //类型：String  可有字段  备注：患者职业ID
            "patientOccupation": "", //类型：String  可有字段  备注：患者职业
            "patientEduId": biglist.tblDiacrisisInfo.patientEduId, //类型：String  可有字段  备注：患者学历ID
            "patientEdu": "", //类型：String  可有字段  备注：患者学历
            "spouseAge": biglist.tblDiacrisisInfo.spouseAge, //类型：String  可有字段  备注：配偶年龄
            "spouseOccupationId": biglist.tblDiacrisisInfo.spouseOccupationId, //类型：String  可有字段  备注：配偶职业ID
            "spouseOccupation": "", //类型：String  可有字段  备注：配偶职业
            "spouseEduId": biglist.tblDiacrisisInfo.spouseEduId, //类型：String  可有字段  备注：配偶学历ID
            "spouseEdu": "", //类型：String  可有字段  备注：配偶学历
            "lastMenses": biglist.tblDiacrisisInfo.lastMenses, //类型：String  可有字段  备注：末次月经时间
            "expectedDate": biglist.tblDiacrisisInfo.expectedDate, //类型：String  可有字段  备注：预产期
            "gestCount": biglist.tblDiacrisisInfo.gestCount, //类型：Number  可有字段  备注：怀孕次数
            "prodCount": biglist.tblDiacrisisInfo.prodCount, //类型：Number  可有字段  备注：生产次数
            "aboCount": biglist.tblDiacrisisInfo.aboCount, //类型：String  可有字段  备注：流产次数
            "liveCount": "1", //类型：String  可有字段  备注：存活次数
            "gestWeeks": biglist.tblDiacrisisInfo.gestWeeks, //类型：String  可有字段  备注：孕龄周
            "gestDays": biglist.tblDiacrisisInfo.gestDays, //类型：String  可有字段  备注：孕龄天
            "impgTypeId": biglist.tblDiacrisisInfo.impgTypeId, //类型：String  可有字段  备注：受孕方式ID
            "impgTypeName": "", //类型：String  可有字段  备注：受孕方式
            "familyMedical": biglist.tblDiacrisisInfo.familyMedical, //类型：String  可有字段  备注：家族史
            "specialMedicalId": biglist.tblDiacrisisInfo.specialMedicalId, //类型：String  可有字段  备注：特殊病史ID
            "specialMedical": "", //类型：String  可有字段  备注：特殊病史
            "badGestId": biglist.tblDiacrisisInfo.badGestId, //类型：String  可有字段  备注：不良孕产史ID
            "badGest": "", //类型：String  可有字段  备注：不良孕产史
            "drugUseId": biglist.tblDiacrisisInfo.drugUseId, //类型：String  可有字段  备注：孕期用药史ID
            "drugUse": "", //类型：String  可有字段  备注：孕期用药史
            "drugUseRemark": biglist.tblDiacrisisInfo.drugUseRemark, //类型：String  可有字段  备注：用药史备注
            "fetusesTypeId": mini.get('changechaosheng').getValue(), //类型：String  可有字段  备注：胎类型ID
            "fetusesType": "", //类型：String  可有字段  备注：胎类型
            "fetusesNo": duotaishu, //类型：Number  可有字段  备注：胎数
            "isValid": isValid, //类型：String  可有字段  备注：是否有效
            "isTransfer": "", //类型：String  可有字段  备注：是否转诊
            "bespeakId": biglist.tblDiacrisisInfo.bespeakId, //类型：String  可有字段  备注：预约内容ID
            "bespeakContent": "", //类型：String  可有字段  备注：预约内容
            "transferProvinceId": biglist.tblDiacrisisInfo.transferProvinceId, //类型：String  可有字段  备注：转诊省份ID
            "transferProvince": "", //类型：String  可有字段  备注：转诊省份
            "transferCityId": biglist.tblDiacrisisInfo.transferCityId, //类型：String  可有字段  备注：转诊市别ID
            "transferCity": "", //类型：String  可有字段  备注：转诊市别
            "transferCountyId": biglist.tblDiacrisisInfo.transferCountyId, //类型：String  可有字段  备注：转诊区县ID
            "transferCounty": "", //类型：String  可有字段  备注：转诊区县
            "patientAddress": biglist.tblDiacrisisInfo.patientAddress, //类型：String  可有字段  备注：患者住址
            "patientTel": biglist.tblDiacrisisInfo.patientTel, //类型：String  可有字段  备注：患者电话
            "spouseTel": biglist.tblDiacrisisInfo.spouseTel, //类型：String  可有字段  备注：配偶电话
            "spouseName": biglist.tblDiacrisisInfo.spouseName, //类型：String  可有字段  备注：配偶姓名
            "spouseCardId": biglist.tblDiacrisisInfo.spouseCardId, //类型：String  可有字段  备注：配偶身份证号
            "diacrisisRemark": ""
        }, //类型：String  可有字段  备注：诊断备注
        //孕检信息
        "diacrisisAssay": [ //类型：Array  可有字段  备注：检验结果
            { //类型：Object  可有字段  备注：检验结果
                "assayId": assayId,
                "niptTypeId": biglist.diacrisisAssay[0].niptTypeId, //类型：String  可有字段  备注：NIPT_ID
                "niptTypeName": "", //类型：String  可有字段  备注：NIPT类型
                "tangScreenId": biglist.diacrisisAssay[0].tangScreenId, //类型：String  可有字段  备注：唐筛ID
                "tangScreenName": "", //类型：String  可有字段  备注：唐筛名称
                "sbp": biglist.diacrisisAssay[0].sbp, //类型：Number  可有字段  备注：收缩压
                "dbp": biglist.diacrisisAssay[0].dbp, //类型：Number  可有字段  备注：舒张压
                "tpr": biglist.diacrisisAssay[0].tpr, //类型：Number  可有字段  备注：体温
                "bloodTypeId": biglist.diacrisisAssay[0].bloodTypeId, //类型：String  可有字段  备注：血型ID
                "bloodTypeName": "", //类型：String  可有字段  备注：血型
                "btNatureId": biglist.diacrisisAssay[0].btNatureId, //类型：String  可有字段  备注：血型性极ID
                "btNatureName": "", //类型：String  可有字段  备注：血型性极
                "antibodyNatureId": biglist.diacrisisAssay[0].antibodyNatureId, //类型：String  可有字段  备注：不规则抗体ID
                "antibodyNatureName": "", //类型：String  可有字段  备注：不规则抗体性极
                "assayRemark": biglist.diacrisisAssay[0].assayRemark, //类型：String  可有字段  备注：备注
                "infectionScreenId": biglist.diacrisisAssay[0].infectionScreenId
            }
        ],
        //卡号信息
        "diacrisisCard": [ //类型：Array  必有字段  备注：患者就诊卡
            { //类型：Object  必有字段  备注：患者就诊卡
                "cardTypeId": biglist.diacrisisCard[0].cardTypeId, //类型：String  必有字段  备注：卡类型ID
                "cardTypeName": "", //类型：String  必有字段  备注：卡类型名称
                "cardNo": biglist.diacrisisCard[0].cardNo //类型：String  必有字段  备注：卡号
            }
        ],
        //居住环境
        "patientlive": patientlive,
        //现存孩信息
        "existingChild": biglist.existingChild,
        //多胎信息
        "diacrisisFetus": biglist.fetusDetail
    }
    var fileArray = document.querySelector('#thisnibaba');
    var formData = new FormData();
    formData.append("json", JSON.stringify(dataJson));
    for (var i = 0, f; f = fileArray.files[i]; i++) {
        formData.append("file", f);
    }
    if (panduan === "1") {
        $.ajax({
            url: SVR_PATH+"cqzd/do/diacinfo/addDiacrisisInfo",
            data: formData,
            type: "POST",
            processData: false,
            contentType: false,
            success: function(data) {
                mini.hideMessageBox(loadingWin);
                if(data.errMsg){
                    mini.alert("新增失败,"+data.errMsg);
                    return;
                }
                mini.alert("新增成功")
                setTimeout(function () {
                    location.reload();
                },500);


                //加载历史数据
                loadlishi("", "1")
                //加载右侧新入数据
                loadxinru("", "1")
            },
            error: function(e) {
                mini.hideMessageBox(loadingWin);
                mini.alert("新增失败")
            }
        });
    } else {
        $.ajax({
            url: SVR_PATH+"cqzd/do/diacinfo/updateDiacrisisInfo",
            data: formData,
            type: "POST",
            processData: false,
            contentType: false,
            success: function(data) {
                mini.hideMessageBox(loadingWin);
                if(data.errMsg){
                    mini.alert("修改失败,"+data.errMsg);
                    return;
                }
                mini.alert("修改成功");
                //加载历史数据
                loadlishi("", "1")
                //加载右侧新入数据
                loadxinru("", "1")
            },
            error: function(e) {
                mini.hideMessageBox(loadingWin);
                mini.alert("修改失败")
            }
        });
    }
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
//身份证校验
function onIDCardsValidation(e) {
    if (e.isValid && e.value) {
        var regIdCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if (!regIdCard.test(e.value)) {
            e.errorText = "身份证输入有误";
            e.isValid = false;
        }
    }
}
// ---------------------------------------------------------------------------------------------右侧事件
var rightmenushow = true;
//加载右侧用户数据
$(function() {
        if (window.top === window.self) { // are you trying to put self in an iframe?
            panduan = "2";
            var getParameters = function (url) {
                var nameValues = [];
                if (url) {
                    if (url.indexOf('?') == -1) {
                        return nameValues.push({ baseUrl: url });
                    };
                    var arrUrlParts = url.split('?');
                    var baseUrl = arrUrlParts[0];
                    var urlParameters=arrUrlParts[1].split('&');
                    for (var i = 0; i < urlParameters.length; i++) {
                        var nameValue = urlParameters[i].split('=');
                        nameValues.push({ baseUrl: baseUrl, key: nameValue[0], urlvalue: nameValue[1]});
                    };
                    return nameValues;
                };
            };
            var userid=getParameters(window.location.href)[0].urlvalue
            var form = new mini.Form("#updatezdxx");
            // console.log(userid)
            $.ajax({
                type: "get",
                dataType: "json",
                url: SVR_PATH+"cqzd/do/diacinfo/getDiacrisisInfo/" + userid,
                data: {},
                success: function(result) {
                    $(".zhezhao").fadeOut(1000);
                    outpatientNo = result.data.tblDiacrisisInfo.outpatientNo;
                    isValid = result.data.tblDiacrisisInfo.isValid;
                    changeButton(isValid)
                    form.setData(result.data);
                    var jzhj = [];
                    for (var i = 0; i < result.data.patientlive.length; i++) {
                        jzhj.push({ "id": result.data.patientlive[i].patientLiveId })
                    }
                    result.data.patientlive = jzhj;
                    mini.get("jzhjselect").selects(jzhj);
                    $('.xchlist').empty();
                    if (result.data.diacrisisAssay.length > 0) {
                        assayId = result.data.diacrisisAssay[0].assayId;
                    }
                    diacrisisId = result.data.tblDiacrisisInfo.diacrisisId;
                    for (var f = 0; f < result.data.existingChild.length; f++) {
                        $('.xchlist').append($("#demo").tmpl(result.data.existingChild[f]));
                        xchgs++;
                    }
                    if (result.data.diacrisisFetus.length > 0) {
                        if (result.data.tblDiacrisisInfo.fetusesTypeId === 1) { //回填单胎数据
                            mini.get("dantaitabs").removeAll();
                            dtjccs = 0;
                            for (var i = 0; i < result.data.diacrisisFetus[0].fetusDetail.length; i++) {
                                inserttab();
                            }
                            //单胎获取数据
                            var dantaiform = new mini.Form("#dantaiform");
                            dantaiform.setData(result.data.diacrisisFetus[0]);
                        } else { //回填多胎数据
                            var duotaidata = result.data.diacrisisFetus;
                            $(".duotaishutab1").empty();
                            duotaishu = 0;
                            for (var dt = 0; dt < duotaidata.length; dt++) {
                                //增加上面的基本信息
                                $(".duotaishutab1").append($("#duotaitab1").tmpl({ indexs: dt + 1, inde: dt }));
                                duotaishu++;
                            }
                            duotaijianchas = 0;
                            mini.get("duotaitabs").removeAll();
                            for (var jcs = 0; jcs < duotaidata[0].fetusDetail.length; jcs++) {
                                insertduotaitab();
                            }
                            var fetusDetail = {
                                "inspectTime": duotaidata[0].inspectTime,
                                "gestWeeks": duotaidata[0].gestWeeks,
                                "gestDays": duotaidata[0].gestDays,
                                "inspectionHospital": duotaidata[0].inspectionHospital,
                                "chorionicId": duotaidata[0].chorionicId,
                                "test": [],
                                "test1": []
                            };
                            for (var i = 0; i < duotaidata.length; i++) {
                                var jcsj = {
                                    "nt": duotaidata[i].nt,
                                    "crl": duotaidata[i].crl,
                                    "isNasal": duotaidata[i].isNasal,
                                    "siteId": duotaidata[i].siteId,
                                    "fetusId": duotaidata[i].fetusId,
                                    "bAbnormalId": duotaidata[i].bAbnormalId,
                                    "fetusRemark": duotaidata[i].fetusRemark
                                };
                                fetusDetail.test.push(jcsj);
                            }
                            for (var ts = 0; ts < duotaidata.length; ts++) {

                                var dcjcsj = {
                                    "inspectionTime": duotaidata[ts].fetusDetail[0].inspectionTime,
                                    "gestWeeks": duotaidata[ts].fetusDetail[0].gestWeeks,
                                    "gestDays": duotaidata[ts].fetusDetail[0].gestDays,
                                    "inspectionHospital": duotaidata[ts].fetusDetail[0].inspectionHospital,
                                    "ctest": []
                                }
                                fetusDetail.test1.push(dcjcsj);
                            }
                            for (var j = 0; j < duotaidata[0].fetusDetail.length; j++) {
                                for (var ts = 0; ts < duotaidata.length; ts++) {
                                    fetusDetail.test1[j].ctest.push(duotaidata[ts].fetusDetail[j])
                                }
                            }
                            var duotaiform = new mini.Form("#duotaiform");
                            duotaiform.setData({ "fetusDetail": fetusDetail });
                        }
                    }
                    txkui.parse();
                    mini.parse();
                    onDeptChanged(mini.get("deptCombo"));
                    onpositionChange(mini.get("positionCombo"));
                }
            });

        }
        mini.get("mingzuid").setData(nation_data)
        diqujazai();
        //加载历史数据
        loadlishi("", "1")
        //加载右侧新入数据
        loadxinru("", "1")
    })
    //右侧新入菜单点击
function rightuserclick(el) {
    $(".userclick").removeClass("userclick");
    $(el).addClass("userclick")
    panduan = "1";
    $(".zhezhao").fadeOut(1000);
    clearform(); //清空表单
    var patientId = $(el).children('.thisuserid').html();
    var hisIdtj = $(el).children('.thishisid').html();
    mini.get("mingzuid").setValue("1");
    mini.get("jzhjselect").selects("1");
    mini.get("infectionScreenId").selects("2,4,6,8");
    diacrisisId="";
    $.ajax({
        type: "get",
        dataType: "json",
        url: SVR_PATH+"cqzd/do/diacinfo/getHisOne/" + hisIdtj,
        data: {},
        success: function(result) {
            outpatientNo = result.data.outpatientNo;
            patientCode = result.data.patientId;
            patientCardId = result.data.patientCardId;
            patientBirthday=result.data.patientBirthday;
            patientHisId=result.data.hisId;
            isValid ="1";
            $("#ZFAndHF").css("display","none")
            mini.get("patientName").setValue(result.data.patientName)
            mini.get("patientCardId").setValue(result.data.patientCardId)
            mini.get("cardNo").setValue(result.data.cardCode)
            mini.get("cardTypeId").setValue(result.data.cardTypeId)
            mini.get("patientAge").setValue(result.data.patientAge)
        }
    });
}
//右侧历史菜单点击
function rightlishiuserclick(el) {
    $(".userclick").removeClass("userclick");
    $(el).addClass("userclick")
    panduan = "2";
    $(".zhezhao").fadeOut(1000);
    var userid = $(el).children('.thisuserid').html();
    var form = new mini.Form("#updatezdxx");
    $.ajax({
        type: "get",
        dataType: "json",
        url: SVR_PATH+"cqzd/do/diacinfo/getDiacrisisInfo/" + userid,
        data: {},
        success: function(result) {
            outpatientNo = result.data.tblDiacrisisInfo.outpatientNo;
            isValid = result.data.tblDiacrisisInfo.isValid;
            changeButton(isValid)
            form.setData(result.data);
            var jzhj = [];
            for (var i = 0; i < result.data.patientlive.length; i++) {
                jzhj.push({ "id": result.data.patientlive[i].patientLiveId })
            }
            result.data.patientlive = jzhj;
            mini.get("jzhjselect").selects(jzhj);
            $('.xchlist').empty();
            if (result.data.diacrisisAssay.length > 0) {
                assayId = result.data.diacrisisAssay[0].assayId;
            }
            diacrisisId = result.data.tblDiacrisisInfo.diacrisisId;
            patientCardId = result.data.tblDiacrisisInfo.patientCardId;

            for (var f = 0; f < result.data.existingChild.length; f++) {
                $('.xchlist').append($("#demo").tmpl(result.data.existingChild[f]));
                xchgs++;
            }
            if (result.data.diacrisisFetus.length > 0) {
                if (result.data.tblDiacrisisInfo.fetusesTypeId === 1) { //回填单胎数据
                    mini.get("dantaitabs").removeAll();
                    dtjccs = 0;
                    for (var i = 0; i < result.data.diacrisisFetus[0].fetusDetail.length; i++) {
                        inserttab();
                    }
                    //单胎获取数据
                    var dantaiform = new mini.Form("#dantaiform");
                    dantaiform.setData(result.data.diacrisisFetus[0]);
                    for (var i=0;i<result.data.diacrisisFetus[0].fetusDetail.length;i++){
                        // console.log('sss---'+result.data.diacrisisFetus[0].fetusDetail[i].fetusDetailId)
                        mini.getByName('fetusDetail['+i+'].bAbnormalId').setValue(result.data.diacrisisFetus[0].fetusDetail[i].fetusDetailId)
                    }
                } else { //回填多胎数据
                    var duotaidata = result.data.diacrisisFetus;
                    $(".duotaishutab1").empty();
                    duotaishu = 0;
                    for (var dt = 0; dt < duotaidata.length; dt++) {
                        //增加上面的基本信息
                        $(".duotaishutab1").append($("#duotaitab1").tmpl({ indexs: dt + 1, inde: dt }));
                        duotaishu++;
                    }
                    duotaijianchas = 0;
                    mini.get("duotaitabs").removeAll();
                    for (var jcs = 0; jcs < duotaidata[0].fetusDetail.length; jcs++) {
                        insertduotaitab();
                    }
                    var fetusDetail = {
                        "inspectTime": duotaidata[0].inspectTime,
                        "gestWeeks": duotaidata[0].gestWeeks,
                        "gestDays": duotaidata[0].gestDays,
                        "inspectionHospital": duotaidata[0].inspectionHospital,
                        "chorionicId": duotaidata[0].chorionicId,
                        "test": [],
                        "test1": []
                    };
                    for (var i = 0; i < duotaidata.length; i++) {
                        var jcsj = {
                            "nt": duotaidata[i].nt,
                            "crl": duotaidata[i].crl,
                            "isNasal": duotaidata[i].isNasal,
                            "siteId": duotaidata[i].siteId,
                            "fetusId": duotaidata[i].fetusId,
                            "bAbnormalId": duotaidata[i].bAbnormalId,
                            "fetusRemark": duotaidata[i].fetusRemark
                        };
                        fetusDetail.test.push(jcsj);
                    }
                    for (var ts = 0; ts < duotaidata.length; ts++) {

                        var dcjcsj = {
                            "inspectionTime": duotaidata[ts].fetusDetail[0].inspectionTime,
                            "gestWeeks": duotaidata[ts].fetusDetail[0].gestWeeks,
                            "gestDays": duotaidata[ts].fetusDetail[0].gestDays,
                            "inspectionHospital": duotaidata[ts].fetusDetail[0].inspectionHospital,
                            "ctest": []
                        }
                        fetusDetail.test1.push(dcjcsj);
                    }
                    for (var j = 0; j < duotaidata[0].fetusDetail.length; j++) {
                        for (var ts = 0; ts < duotaidata.length; ts++) {
                            fetusDetail.test1[j].ctest.push(duotaidata[ts].fetusDetail[j])
                        }
                    }
                    var duotaiform = new mini.Form("#duotaiform");
                    duotaiform.setData({ "fetusDetail": fetusDetail });
                    for (var i=0;i<duotaidata.length;i++){
                        for (var j=0;j<duotaidata[i].fetusDetail.length;j++){
                            mini.getByName('fetusDetail.test1['+i+'].ctest['+j+'].bAbnormalId').setValue(duotaidata[i].fetusDetail[j].bAbnormalId)
                        }
                    }



                }
            }
            txkui.parse();
            mini.parse();
            onDeptChanged(mini.get("deptCombo"));
            onpositionChange(mini.get("positionCombo"));
        }
    });
}
//右侧是否显示点击
$('.zdmenubuttom').click(function() {
        if (rightmenushow) {
            $('.rightmenu').animate({
                width: 'toggle'
            }, 350);
            $('.zdmenubuttom').children("img").attr("src", "../img/show.png")
            rightmenushow = false;
        } else {
            $('.rightmenu').animate({
                width: 'toggle'
            }, 350);
            $('.zdmenubuttom').children("img").attr("src", "../img/hide.png")
            rightmenushow = true;
        }

    })
    //点击其他地方隐藏右侧
$(".bottoncon,.topstate,.bottonbuttom").click(function() {
        if (rightmenushow) {
            $('.rightmenu').animate({
                width: 'toggle'
            }, 350);
            rightmenushow = false;
        }
    })
    //右侧点击title按钮
$('.righttitle').click(function() {
        $(this).next().animate({
            height: 'toggle'
        }, 350);
    })
    // -------------------------------------------------------------------------------------------------
    //----------------------------------------------------------------------现存孩---------------------------------

//新增现存孩
$('.addxchtab').click(function() {
        xchgs++;
        $('.xchlist').append($("#demo").tmpl());
        mini.parse();
    })
    //删除现存孩
var dropschtab = function(el) {
    if (xchgs > 0) {
        xchgs--;
        $(el).parent().remove();
    }
}
$('.backClick').css('background', '#dcdcdc')
$('.submitClick').css('background', '#dcdcdc')

//加载地区省
var diqujazai = function() {
    var sheng = [];
    for (var s = 0; s < dqdatas.length; s++) {
        sheng.push({ "id": s, "name": dqdatas[s].name });
    }
    mini.get("deptCombo").setData(sheng)
}
var shiindex = 0;
//转诊地省点击
function onDeptChanged(el) {
    var shidata = [];
    shiindex = el.value;
    for (var i = 0; i < dqdatas[el.value].city.length; i++) {
        var id = i;
        var name = dqdatas[el.value].city[i].name;
        shidata.push({ "id": id, "name": name })
    }
    mini.get("positionCombo").setData(shidata)
    mini.parse();
}
//转诊地市点击
function onpositionChange(el) {
    var xiandata = [];
    for (var i = 0; i < dqdatas[shiindex].city[el.value].area.length; i++) {
        var id = shiindex + "" + el.value + "" + i;
        var name = dqdatas[shiindex].city[el.value].area[i];
        xiandata.push({ "id": id, "name": name })
    }
    mini.get("xianCombo").setData(xiandata)
    mini.parse();
}
//清空表单
function clearform() {
    var form = new mini.Form("#updatezdxx");
    form.clear();
    $('.xchlist').empty();
    $('.xchlist').append($("#demo").tmpl());
    xchgs++;
    mini.get("dantaitabs").removeAll();
    dtjccs = 0;
    inserttab();
    $(".duotaishutab1").empty();
    duotaishu = 0;
    $(".duotaishutab1").append($("#duotaitab1").tmpl({ indexs: duotaishu + 1, inde: duotaishu }));
    duotaishu++;
    duotaijianchas = 0;
    mini.get("duotaitabs").removeAll();
    insertduotaitab();
    txkui.parse();
}
//关闭单胎
function closedantai() {
	var form2 = new mini.Form("#dantaiform");
	if (form2.isValid() == false){
		mini.alert("请确认您的数据")
		return;
	};
    $('.dantaidiv').css('display', 'none');
}
function closedantai1() {
	mini.get("changechaosheng").setValue("")
	$('.dantaidiv').css('display', 'none');
}
//关闭多胎
function closeduotai() {
	var form1 = new mini.Form("#duotaiform");
	if (form1.isValid() == false){
		mini.alert("请确认您的数据");
		return;
	};
    $('.duotaidiv').css('display', 'none')
}
function closeduotai1() {
	mini.get("changechaosheng").setValue("")
    $('.duotaidiv').css('display', 'none')
}
//加载右侧历史数据
function loadlishi(key, isValid) {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: SVR_PATH + "cqzd/do/diacinfo/queryDiacrisisInfo",
        data: {
            'key': key,
            "isValid": isValid
        },
        success: function(result) {
            var ghlist = result;
            for(var i=0;i<ghlist.data.length;i++){
                if(ghlist.data[i].isValid==="2"){
                    ghlist.data[i].isValid="isValid"
                }else{
                    ghlist.data[i].isValid=""
                }
            }
            $('.lishiguahao').empty();
            $('.lishiguahao').append($("#lishiuser").tmpl(ghlist));
        }
    });
}
//加载右侧新入数据
function loadxinru(key, isValid) {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: SVR_PATH + "cqzd/do/diacinfo/gethis",
        data: {
            'key': key
        },
        success: function(result) {
            var ghlist = result;
            for(var i=0;i<ghlist.data.length;i++){
                if(ghlist.data[i].isValid==="2"){
                    ghlist.data[i].isValid="isValid"
                }else{
                    ghlist.data[i].isValid=""
                }
            }
            $('.xinruguahao').empty();
            $('.xinruguahao').append($("#user").tmpl(ghlist));
        },
    });
}
//右侧搜索
function changeselect() {
    var selectkey = $(".thisrightselect").val();
    var selectvalid = $('.zuofeicheck').is(':checked');
    var valid = 1;
    if (selectvalid) {
        valid = null;
    }
    loadxinru(selectkey, valid);
    loadlishi(selectkey, valid);
}
//打开病例管理
function onclick4() {
    $(".tanchuang").css("display", "flex");
    loadwjxx(diacrisisId)
}
//关闭病例管理
function closeBLZL() {
    $(".tanchuang").css("display", "none");
}
//点击病例查询
function loadwjxx(diacrisisId) {
    $.ajax({
        type: "get",
        dataType: "json",
        url: SVR_PATH+"cqzd/do/diacfile/getFileByFkId/" + diacrisisId,
        data: {},
        success: function(result) {
            var files_grid = mini.get("files_grid");
            files_grid.setData(result.data)
        }
    });
}
//兵力管理里面的a标签
function onActionRenderer(e) {
    var row = e.row;
    var aa = row.fileName;
    var s = '<a href="'+SVR_PATH+'cqzd/do/diacfile/getFileByCode/' + row.fileCode + '">' + aa + '</a>';
    return s;

}
//删除多胎胎数
function delduotai(el) {
    if (duotaishu == 1) {
        return;
    }
    duotaishu--;
    var tabs = mini.get("duotaitabs");
    for (var s = 0; s < tabs.getTabs().length; s++) {
        var deltab = tabs.getTabBodyEl(tabs.getTab(s));
        var tabcondiv = $(deltab).find(".tab1conten")

        tabcondiv.children("table:last-child").remove();
        tabcondiv.children("span:last-child").remove();
    }
    $(el).parent().parent().prev().children("td:last-child").append("<span class='delduotai' onclick='delduotai(this)'>X</span>")
    $(el).parent().parent().next().remove();
    $(el).parent().parent().remove();
}

//居住环境选择事件
mini.get("jzhjselect").on("valuechanged",function(){
    if(mini.get("jzhjselect").getValue()==="1"){

    }else{

    }
})

//末次月经选择事件  
mini.get("lastMenses").on("valuechanged",function(){
    var lastmendata=mini.get("lastMenses").getValue();
    var recordTimedata=mini.get("recordTime").getValue();
    changeRecordAndLast(recordTimedata,lastmendata)
    var XZdata=getMyDate(lastmendata)//格式化之后的时间
    var ycqdata=addDate(XZdata,280)//预产期
    mini.get("expectedDate").setValue(ycqdata)
})
//登记时间选择事件
mini.get("recordTime").on("valuechanged",function(){
    var lastmendata=mini.get("lastMenses").getValue();
    var recordTimedata=mini.get("recordTime").getValue();
    changeRecordAndLast(recordTimedata,lastmendata)
})
function changeRecordAndLast(recordTimedata,lastmendata) {
    if(!lastmendata){
        return;
    }else if(!recordTimedata){
        return;
    }
    var dataInterval=datedifference(lastmendata,recordTimedata)
    var ylweed=parseInt(dataInterval/7);//孕龄周
    var ylday=dataInterval%7;//孕龄天
    mini.get("gestWeeks").setValue(ylweed)
    mini.get("gestDays").setValue(ylday)
}

//根据数据有效性定义作废恢复按钮
function changeButton(vals){
    $("#ZFAndHF").css("display","block")
    if(vals==="1"){
        mini.get("ZFAndHF").setText("作废")
    }else {
        mini.get("ZFAndHF").setText("恢复")
    }
}
function deletethis(el){
    if(mini.get("ZFAndHF").getText()==="作废"){
        isValid="2"
    }else{
        isValid="1"
    }
    onclick3();
}


//导出
function exportThis() {
    window.open('/cqzd/Diagnosis/selDiagnosisAll?patientCardId='+patientCardId)
}